<?php
/**
 * @var View $this
 * @var ArrayDataProvider $dataProvider
 */

use backend\components\widget\adminLTE\GridView;
use yii\data\ArrayDataProvider;
use backend\components\helper\EasyHtml;
use backend\modules\log\Log;
use yii\web\View;

$this->title = '错误日志';

?>
<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header with-border">
                <h3 class="box-title"><?= EasyHtml::encode($this->title) ?></h3>
            </div>
            <div class="box-tools form-inline">
                <div class="box-body">
                    <?= GridView::widget([
                        'layout' => '{items}',
                        'dataProvider' => $dataProvider,
                        'columns' => [
                            [
                                'label' => '文件名称',
                                'attribute' => 'name',
                                'format' => 'raw',
                                'value' => function (Log $log) {
                                    return EasyHtml::tag('h5', join("\n", [
                                        EasyHtml::encode($log->name),
                                        '<br/>',
                                        EasyHtml::tag('small', EasyHtml::encode($log->fileName)),
                                    ]));
                                },
                            ],
                            [
                                'label' => '统计',
                                'attribute' => 'counts',
                                'format' => 'raw',
                                'headerOptions' => ['class' => 'sort-ordinal'],
                                'value' => function (Log $log) {
                                    return $this->render('_counts', ['log' => $log]);
                                },
                            ],
                            [
                                'label' => '大小',
                                'attribute' => 'size',
                                'format' => 'shortSize',
                                'headerOptions' => ['class' => 'sort-ordinal'],
                            ],
                            [
                                'label' => '更新时间',
                                'attribute' => 'updatedAt',
                                'format' => 'relativeTime',
                                'headerOptions' => ['class' => 'sort-numerical'],
                            ],
                            [
                                'header' => '操作',
                                'class' => '\yii\grid\ActionColumn',
                                'template' => '{history} {view} {archive} {delete}',
                                'urlCreator' => function ($action, Log $log) {
                                    return [$action, 'slug' => $log->slug];
                                },
                                'buttons' => [
                                    'history' => function ($url) {
                                        return EasyHtml::iconLink('记录', $url, [
                                            'icon' => 'list-ul',
                                            'class' => 'btn btn-xs btn-primary',
                                        ]);
                                    },
                                    'view' => function ($url, Log $log) {
                                        return !$log->isExist ? '' : EasyHtml::iconLink('查看', $url, [
                                            'icon' => 'eye',
                                            'class' => 'btn btn-xs btn-success',
                                            'target' => '_blank',
                                        ]);
                                    },
                                    'archive' => function ($url, Log $log) {
                                        return !$log->isExist ? '' : EasyHtml::iconLink('归档', $url, [
                                            'icon' => 'file-zip-o',
                                            'class' => 'btn btn-xs btn-danger',
                                            'data' => [
                                                    'method' => 'post',
                                                    'confirm' => '确定要执行此操作吗?'
                                            ],
                                        ]);
                                    },
                                    'delete' => function ($url) {
                                        return EasyHtml::iconLink('删除', $url, [
                                            'icon' => 'trash-o',
                                            'class' => 'btn btn-xs btn-danger',
                                            'data' => [
                                                'method' => 'post',
                                                'confirm' => '确定要执行此操作吗?'
                                            ],
                                        ]);
                                    },
                                ],
                            ],
                        ],
                    ]) ?>
                </div>
            </div>
        </div>
    </div>
</div>
